package com.foxmail.aroundme.boring.base.present;

import com.foxmail.aroundme.boring.base.view.BaseView;
import com.foxmail.aroundme.boring.callback.RequestCallback;
import com.foxmail.aroundme.boring.utils.m_enum.RefreshType;
import com.foxmail.aroundme.boring.utils.m_enum.RequestErrorType;

import rx.Subscription;

/**
 * Created by gzl on 12/20/16.
 *
 * V为BaseView子类，T为数据类型
 *
 * 基类主要是为了继承此类的子类的Ｖ层和Ｍ层的控制
 */

public class BasePreImpl<V extends BaseView, T> implements BasePre, RequestCallback<T>{

    protected Subscription mSubscription;

    protected V mView;

    public BasePreImpl(V view) {
        this.mView = view;
    }

    @Override
    public void onResume() {

    }

    @Override
    public void onDestroy() {
        if (mSubscription != null && !mSubscription.isUnsubscribed()) {
            mSubscription.unsubscribe();
        }
        mView = null;
    }

    @Override
    public void unSubscription() {
        if (mSubscription != null && !mSubscription.isUnsubscribed()) {
            mSubscription.unsubscribe();
        }
    }

    /**
     * 开始返回之前先要显示Progress
     */

    @Override
    public void beforeRequest(@RefreshType.Refresh int type) {
        if (mView != null) {
            mView.showProgress(type);
        }
    }

    /**
     * 失败返回
     * @param msg 错误信息
     * @param error
     */
    @Override
    public void requestError(String msg, @RequestErrorType.Request int error) {

    }

    @Override
    public void requestComplete() {

    }

    @Override
    public void requestSuccess(T data) {

    }

    @Override
    public void requestSuccess(T data, String channelId, boolean isCache) {

    }
}
